package com.google.guava;

import cn.hutool.core.util.StrUtil;
import com.google.common.base.Splitter;
import org.junit.Test;

import java.util.Iterator;

/**
 * guava 字符串处理 CharMatcher/Joins/Splitter
 *
 * @author 宫静雨
 * @version 1.0
 * @since 2023-08-26 20:25:34
 */
public class StringTest {
    String s = "\"account_period\",\n" +
            "\"process_month\",\n" +
            "\"order_code\",\n" +
            "\"client_code\",\n" +
            "\"land_province_code\",\n" +
            "\"landing_province\",\n" +
            "\"land_city_code\",\n" +
            "\"landing_city\",\n" +
            "\"fee_type\",\n" +
            "\"user_out_account_pre_tax\",\n" +
            "\"tax_rate\",\n" +
            "\"client_name\",\n" +
            "\"pay_amount\",\n" +
            "\"pay_time\",\n" +
            "\"refund_id\",\n" +
            "\"refund_fee\",\n" +
            "\"refund_time\",\n" +
            "\"cust_type\",\n" +
            "\"service_type\",\n" +
            "\"cust_id\",\n" +
            "\"phone\",\n" +
            "\"pay_mode\",\n" +
            "\"refund_mode\",\n" +
            "\"record_id\",\n" +
            "\"CONTRACT_CITY_NAME\",\n" +
            "\"FILE_NAME\",\n" +
            "\"MONTH\"";

    @Test
    public void test3() {
        String s1 = StrUtil.cleanBlank(s).replaceAll("\"", "").replaceAll(",", "|");
        System.out.println(s1);
    }

    @Test
    public void test2() {
        String s1 = StrUtil.cleanBlank(s);
        System.out.println(s1);
        String s2 = s1.replaceAll("\"", "");
        String s3 = s2.replaceAll(",", "|");
        System.out.println(s3);
    }

    @Test
    public void test1() {
        Iterable<String> split = Splitter.on(",").omitEmptyStrings().split(s);
        Iterator<String> iterator = split.iterator();
        StringBuilder sb = new StringBuilder();
        while (iterator.hasNext()) {
            String next = iterator.next();
            sb.append(next).append("|");
        }
        System.out.println(sb);
    }
}
